package com.jiliason.segmentation.doMain;

import com.jiliason.segmentation.entity.SegmentInputPojo;
import com.jiliason.segmentation.interfaces.ServiceMaster;
import org.springframework.stereotype.Service;


@Service
public class ServiceMasterImpl implements ServiceMaster {

    private final ServiceCache serviceRepository;

    public ServiceMasterImpl(ServiceCache serviceRepository) {
        this.serviceRepository = serviceRepository;
    }

    @Override
    public String callServiceProc(SegmentInputPojo input){
        return serviceManagement(input);
    }


    private String serviceManagement(SegmentInputPojo input) {
        String response;
        try {
            AbstractService service = serviceRepository.getProcessor(input.getTag(), String.valueOf(input.isStandard()));
            response = service.handle(input);
            return response;
        } catch (Exception e) {
            // TODO: 2023/12/29 日志
            // TODO: 2023/12/29 事务
            e.printStackTrace();
            response = "{}";
        }
        return response;
    }
}
